package com.example.rentsystem.mapper;

import com.example.rentsystem.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

    @Insert("insert into user(name, account, password, phone, role) VALUES(#{name}, #{account}, #{password}, #{phone}, #{role})")
    int addUser(User user);

    @Delete("delete from user where id = #{id}")
    int deleteUser(int id);

    @Select("select * from user")
    List<User> getUsers();

    @Select("select * from user where name like '%' #{name} '%'")
    List<User> findUsersByName(String name);

    @Select("select * from user where name = #{username}")
    User userNameExist(String username);

    @Select("select * from user where account = #{account}")
    User accountExist(String account);

    @Select("select * from user where id = #{id}")
    User getUserById(int id);

    @Select("select * from user where account =#{account} and password = #{password}")
    User getUser(@Param("account") String account, @Param("password") String password);

    @Update("update user set name = #{name}, account = #{account}, phone = #{phone}, password = #{password} where id = #{id}")
    int editUser(User user);
}
